home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
-
- // Procedure Name:
- // precisionPrompt
- //
- // Description Name;
- // Displays a modal dialog to get a decimal precision value
- // from the user.
- //
- // Input Value:
- // $parent - the window to parent the dialog to (empty if none)
- // $oldPrecision - the current value
- // $max - highest allowable value
- //
- // Output Value:
- // 0 = if user cancelled
- // > 0 - the new precision
- //
-
- global proc int precisionPrompt (string $parent, int $oldPrecision, int $max)
- {
- string $returnValue;
- string $precisionStr;
- int $newPrecision = 0;
-
- // Loop until an acceptable integer is entered into the
- // modal prompt dialog (won't accept text garbage)
-
- for (;;) {
-
- if ($parent == "") {
- $returnValue = `promptDialog -title "Change Precision"
- -message "Enter Number of Decimal Places:"
- -text $oldPrecision -button "OK"
- -button "Cancel" -db "OK"`;
- } else {
- $returnValue = `promptDialog -title "Change Precision"
- -message "Enter Number of Decimal Places:"
- -text $oldPrecision -button "OK"
- -button "Cancel" -db "OK"
- -parent $parent`;
- }
-
- if ($returnValue != "OK")
- break;
-
- $precisionStr = `promptDialog -q`;
- $newPrecision = (int) $precisionStr;
-
- // Determine if the number entered is within a reasonable bound
-
- int $isWithinBounds = $newPrecision >= 1 && $newPrecision <= $max;
-
- // Convert the string to an integer and back, and if the string
- // is still the same then the string entered must have been a
- // proper integer. Also, this way float values aren't accepted!
-
- if ($precisionStr == (string) $newPrecision && $isWithinBounds) {
- break;
- } else {
- catch( error( "\"" + $precisionStr +
- "\" is not valid, please enter an integer between 1 and " +
- $max + "." ) );
- }
- }
-
- return $newPrecision;
- }
-